Macromedia MAX 2003 Topic Center

Consuming Web Services with Macromedia Flash MX Professional 2004

Arthur Phillips

Arthur Phillips

www.artswebsite.com

This article is an excerpt from Art Phillips' session (CS203H) at the Macromedia MAX 2003 conference. For sneak peeks of ColdFusion and Dreamweaver sessions, see Simon Slooten's Object-Oriented ColdFusion article and Betsy Bruce's Tableless Layout Using the CSS Box Method. Don't miss out on these sessions or any of MAX 2003! Register now for this year's MAX conference in Salt Lake City November 18-21 . If you can't make it, be sure to check out the live conference coverage during the conference on the MAX Developer Center.

This sneak peak of my MAX session (CS203H) is about a technology that is emerging as a revolutionary tool for web application development, a technology that is an important part of the Macromedia MX 2004 product line—web services.

Web services are the next step in the evolution of distributed computing architectures. Web services enable developers to execute server-side programming from their domain, or from other domains, as if that programming was local to their application. The revolutionary part is the use of web protocols and standards to hook everything together. Using standard web protocols, developers can use web services without knowing or caring which language the service was written in, or which platform the service is running on. A web service description file provides all the information needed to communicate with the service’s programmatic interface. A key concept of the web service model is for developers to construct their web applications by discovering and aggregating web services built by other diverse parties.

While ColdFusion components (CFCs) provide an amazingly simple framework for developing web services (wrap a user-defined function in a cfcomponent tag and set the access attribute to remote), my presentation focuses on using, or, to use the correct vernacular, consuming web services.

Macromedia Flash MX Professional 2004 provides a powerful, rapid development tool for building web service consumers. New tools and components in Flash MX Professional 2004 simplify and speed the development of web service-based applications. Flash exemplifies the Macromedia vision that tools empower developers while freeing them from the pain of mastering complex frameworks.

The ubiquitous Flash Player is an incredible thin client that supports players for a variety of platforms, including Windows, Mac OS, Unix, and mobile devices. True to the vision of web services, the Flash Player can consume services built in any technology, including Macromedia ColdFusion, Java, ASP.NET, and PHP, which are running on any platform.

Building a Web Services Application with Flash

The application you will build in this session provides weather information. It integrates two web services, one for address to zip code lookup and one that returns weather information based on zip code. This aggregation of services enables users to enter either an address or zip code. Client-side logic then invokes the correct service, passes the information between service calls (that is to say, address to zip code to weather service), and returns the weather information.

The finished application looks something like Figure 1.

A custom web services application that provides weather information based on zip code

Figure 1: A custom web services application that provides weather information based on zip code

Here are the general steps involved in consuming a web service in Flash:

  1. Discover a service and obtain the service description file.
  2. Register the service in Flash.
  3. Configure a WebServiceConnector.
  4. Deploy the user interface components.
  5. Bind the user interface components to the service.
  6. Trigger the service call.

Now, let’s examine these steps in some detail

Discover a Service

Just as people now use Google to find web pages, the web services model uses DNS technology to provide directories where people can find web services. These web service directories are called Universal Description, Discovery, and Integration directories or UDDIs for short. Although both IBM and Microsoft have such directories, you can also use the Xmethods UDDI. Xmethods also provides the necessary Web Service Description Language (WSDL) files. These WSDL files provide enough information to allow programs like Macromedia Dreamweaver and Flash to connect to and communicate with the web service.

Register the Service in Flash

By entering the address of the WSDL file in the Flash Web Services Panel the service, as well as its methods and parameters, will be available to Flash components (see Figure 2).

Register the web service in Flash.

Figure 2: Register the web service in Flash.

Configure a WebServiceConnector

The WebServiceConnector is a new Flash component that speeds connection to and implementation of a service. Using the Component Inspector panel you can connect the WebServiceConnector to web services that have been registered in Flash and the appropriate method of the service can be selected (see Figure 3).

Configuring a WebServiceConnector is easy.

Figure 3: Configuring a WebServiceConnector is easy.

Deploy the User Interface Components

Now that the connection is ready, you need to provide any required inputs and handle the results from the service. Macromedia Flash MX Professional 2004 provides a number of powerful user interface components for this task (see Figure 4). These components include the TextInput, TextArea, Label, Combobox, List, and DataGrid components among others. After you put the appropriate user interface components on stage, you are ready to connect or bind them to the service.

You can choose from a variety of powerful user interface components.

Figure 4: You can choose from a variety of powerful user interface components.

Bind the User Interface Components to the Service

Return to the Component Inspector panel and use the Bindings tab to bind the user interface components to the appropriate service parameters.

Bind the user interface components to the appropriate service

Figure 5: Bind the user interface components to the appropriate service.

Trigger the Service Call

Now, all you have to do is trigger the application into life. This can happen automatically, in response to user input or when your app receives results from a service. While the actual code for the trigger is simple, the Behaviors panel provides an easy way to apply the trigger (see Figure 6).

To bring the application to life, you must trigger the service call.

Figure 6: To bring the application to life, you must trigger the service call.

In my full session, I will also show you how to enhance this application with the client-side logic that determines which parameters the user has provided: address or zip code. The logic then decides which service, zip code look up or weather report to call. If you request the address to zip code look-up, the logic passes the returned zip code to both the user interface and the weather service.

I have had a lot of fun building this session. I am sure that those who attend my session will find that working with Macromedia Flash MX Professional 2004 and web services is easy, fun, and exciting.


About the author

Arthur Phillips is currently a Macromedia product specialist for Future Media Concepts. He has been delivering cutting-edge training solutions since 1984. He has an extensive background in video, multimedia, and electronic graphics. Art holds too many certifications as a Macromedia instructor, designer, and developer to list. He was rated top scorer by Macromedia in both his Macromedia Flash and Dreamweaver certifications. He enjoys sharing his knowledge with the public through his classes and his website.